package pt.ipleiria.plp.Lixeiras;

import java.rmi.RemoteException;
import pt.ipleiria.plp.stub.BlackSpotState;
import pt.ipleiria.plp.stub.OperationStatus;
import pt.ipleiria.plp.stub.SpottingSoap_Stub;

/**
 * Class to be used when the only thing wanted is to change the state
 * @author Filipe Felisberto e Ricardo Silva
 */
public class LixeiraChangedState extends LixeiraPending {

    public LixeiraChangedState(String guid, String title,String newState) {

        super(guid, title,newState);
    }

    public LixeiraSendResult send(String app) {
        try {

            SpottingSoap_Stub service = new SpottingSoap_Stub();
            OperationStatus op = service.changeBlackSpotState(getGuid(),
                    BlackSpotState.fromValue(getState()), app);
            if (op.isOperationSuceeded()) {
                System.out.println("id: "+op.getNewId());
                LixeiraSent lix = toSentStatus();
                return new LixeiraSendResult(lix);
            } else {
                return new LixeiraSendResult(op.getErrorMessage());
            }
        } catch (RemoteException ex) {
            ex.printStackTrace();
            return new LixeiraSendResult(ex.getMessage());
        }
    }

    public String delete(String app) {
        return null;
    }
}
